/*******************************************************************************
Title: Individualism during Crisis 
Authors: Bo Bian, Jingjing Li, Ting Xu, Natasha Z. Foutz
Purpose: Produce the following tables and figures
         - Table 1, 2, 4, 5, 6 
         - Appendix Table A2, A3, A4, A6, A7, A9, A10, A11, A12, A14
		 - Figure 1
		 - Appendix Figure A1, A3, A4, A5, A6, A7
*******************************************************************************/

clear all
set more off
set matsize 5000
cap log close
set linesize 200

log using "tables\rep_county_level", replace
use "data\rep_county_level_sample.dta", clear

******************************************************************************** 
* Table 1 (County-level Summary Statistics)
********************************************************************************
* Panel A (social distancing variables from Google Mobility Report)
global gm "pctchg_grocery_phamacy pctchg_workplaces pctchg_retailrecreation pctchg_transit_stations pctchg_parks pctchg_residential" 
tabstat $gm if post_lockdown==1 & tfe_bin<., stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc)

* Panel B (social distancing variables from SafeGraph)
global sg "pct_2km_travelled pct_ft_work pct_pt_work pct_home_gt_76 pct_shelter"
tabstat $sg if tfe_bin<., stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc)

* Panel C (COVID-related GoFundMe Campaigns)
global gfm_sum "count_covid pct_count_covid count_covid_service count_covid_business count_covid_funding100  lnraised_covid pct_covid_funding100"
tabstat $gfm_sum if tfe_bin<., stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc)

* Panel D (Individualism Measures)
tabstat tfe_bin tfe_decade if date==mdy(03,01,2020) & tfe_bin<., stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc)
tabstat infreq_name nonpatmat_name if date==mdy(03,01,2020), stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc) 

******************************************************************************** 
* Table 2 (Individualism and Social Distancing)
********************************************************************************
* Panel A (social distancing variables from Google Mobility Report)
eststo clear
foreach y in $gm {
	eststo `y': quietly reghdfe `y' post_lockdown##c.tfe_bin, ab(fips date#fips_state) cl(fips)
	qui estadd ysumm, mean 
}
esttab $gm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 2 Panel A; fe: county, state x date) keep(1.post*#*) replace

* Table 2B (social distancing variables from SafeGraph)
eststo clear
foreach y in $sg {
	eststo `y': quietly reghdfe `y' post_lockdown##c.tfe_bin, ab(fips date#fips_state) cl(fips)
	qui estadd ysumm, mean 
}
esttab $sg, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 2 Panel B; fe: county, state x date) keep(1.post*#*) replace

******************************************************************************** 
* Table 4 (Individualism and Voluntary Redistribution)
********************************************************************************
* Panel B (baseline)
global gfm "count_noncovid count_covid pct_count_covid count_covid_service count_covid_business lnraised_covid pct_covid_funding100"
eststo clear
foreach y in $gfm {
	eststo `y': quietly reghdfe `y' post_lockdown##c.tfe_bin, ab(fips date#fips_state) cl(fips)
	qui estadd ysumm, mean 
}
esttab $gfm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 4 Panel A; fe: county, state x date) keep(1.post*#*) replace

* Panel B (interaction with Federal Aid)
lab var post_bill "=1 after CARES act (April 12, 2020)"
eststo clear
foreach y in $gfm  {
	eststo `y': quietly reghdfe `y' post_lockdown##c.tfe_bin post_bill##c.tfe_bin, ab(fips fips_state#date) cl(fips)
	qui estadd ysumm, mean 
}
esttab $gfm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 4 Panel B; fe: county, state x date) keep(*1.post*#c.tfe*) replace


******************************************************************************** 
* Table A2 (Table 2B column (5), Table 4 column (3): alternative standard errors)
********************************************************************************
* columns (1) and (3): clustered by state
eststo clear
eststo TA2_1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin, ab(fips date#fips_state) cl(fips_state)
eststo TA2_3: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin, ab(fips date#fips_state) cl(fips_state)
esttab TA2*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A2 columns (1) and (3)) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace 

* columns (2) and (4): bootstrapping (takes time, may generate slightly different standardard errors/t-stat)
egen date_state=group(date fips_state)
g inter=post_lockdown*tfe_bin
reghdfe pct_shelter inter, ab(date_state fips) cl(fips_state)
quietly reghdfe pct_shelter inter i.fips, ab(date_state) cl(fips_state)
boottest inter, reps(999) svmat 
reghdfe pct_count_covid inter, ab(date_state fips) cl(fips_state)
quietly reghdfe pct_count_covid inter i.fips, ab(date_state) cl(fips_state)
boottest inter, reps(999) svmat 
drop inter date_state

******************************************************************************** 
* Table A3 (Table 2, Table 4: alternative specifications)
********************************************************************************
eststo clear
foreach y in $gm $sg $gfm {
	eststo `y': quietly reghdfe `y' post_lockdown##c.tfe_bin, ab(fips date) cl(fips)
	qui estadd ysumm, mean 
}
* Panel A (social distancing variables from Google Mobility Report, county and date FE)
esttab $gm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A3 Panel A; fe: county, date) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace

* Panel C (social distancing variables from SafeGraph, county and date FE)
esttab $sg, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A3 Panel C; fe: county, date) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace

* Panel E (voluntary redistribution from GofundMe, county and date FE)
esttab $gfm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A3 Panel E; fe: county, date) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace

eststo clear
foreach y in $gm $sg $gfm {
	eststo `y': quietly reghdfe `y' post_lockdown##c.tfe_bin [aw=pop], ab(fips date) cl(fips)
	qui estadd ysumm, mean 
}
* Panel B (social distancing variables from Google Mobility Report, county and date FE, weighted by population)
esttab $gm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A3 Panel B; fe: county, date) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace

* Panel D (social distancing variables from SafeGraph, county and date FE, weighted by population)
esttab $sg, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A3 Panel D; fe: county, date) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace

* Panel F (voluntary redistribution from GofundMe, county and date FE, weighted by population)
esttab $gfm, scalars(ymean) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A3 Panel F; fe: county, date) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace

******************************************************************************** 
* Table A4 (Table 2B column (5), Table 4 column (3): alternative weighting)
********************************************************************************
* Panel A (social distancing variables from SafeGraph)
eststo clear
eststo TA4A1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin [aw=gdp], ab(fips date) cl(fips)
eststo TA4A2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin [aw=payroll], ab(fips date) cl(fips)
eststo TA4A3: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin [aw=gdp], ab(fips fips_state#date) cl(fips)
eststo TA4A4: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin [aw=payroll], ab(fips fips_state#date) cl(fips)
esttab TA4A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A4 Panel A) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace 

* Panel B (voluntary redistribution from GofundMe)
eststo clear
eststo TA4B1: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin [aw=gdp], ab(fips date) cl(fips)
eststo TA4B2: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin [aw=payroll], ab(fips date) cl(fips)
eststo TA4B3: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin [aw=gdp], ab(fips fips_state#date) cl(fips)
eststo TA4B4: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin [aw=payroll], ab(fips fips_state#date) cl(fips)
esttab TA4B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A4 Panel B) keep(1.post*#* 1.post*) order (*tfe_bin* *post*) replace 

******************************************************************************** 
* Table 5 (Externality Channel)
********************************************************************************
lab var urban "urban areas (population more than 50,000)"
lab var pop_density_10group "population density (10 groups)"
lab var pct_above70 "the share of population of age 70"
lab var pct_above80 "the share of population of age 80"

* Panel A
eststo clear
eststo T5A1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin##urban [aw=pop], ab(fips fips_state#date) cl(fips)
eststo T5A2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin##c.pop_density_10group [aw=pop], ab(fips fips_state#date) cl(fips)
eststo T5A3: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin##c.pct_above70 [aw=pop], ab(fips fips_state#date) cl(fips)
eststo T5A4: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin##c.pct_above80 [aw=pop], ab(fips fips_state#date) cl(fips)
esttab T5A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 5 Panel A) keep(1.post*#*#* 1.post*#c.tfe* 1.post*#*urban 1.post*#c.*pop* 1.post*#c.*pct*) order(1.post*#*#* 1.post*#c.tfe*) replace

* Panel B (externality - gfm; carried out at the campaign level, see other do files)

******************************************************************************** 
* Table 6 (Polititical Preferences)
********************************************************************************
lab var std_pct_Trump "2016 Trump vote share (standardized)"

* Panel A (effect of TFE on political preferences)
eststo T6A1: quietly reg std_pct_Trump tfe_bin if date==mdy(3,1,2020)
eststo T6A2: quietly reg std_pct_Trump tfe_bin if date==mdy(3,1,2020), ab(fips_state) 
esttab T6A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 6 Panel A) replace

* Panel B (effect of political preferences on social distancing and voluntary redistribution) 
eststo clear
eststo T6B1: quietly reghdfe pct_shelter post_lockdown##c.std_pct_Trump, ab(fips date) cl(fips)
eststo T6B2: quietly reghdfe pct_shelter post_lockdown##c.std_pct_Trump, ab(fips fips_state#date) cl(fips)
eststo T6B3: quietly reghdfe pct_count_covid post_lockdown##c.std_pct_Trump, ab(fips date) cl(fips)
eststo T6B4: quietly reghdfe pct_count_covid post_lockdown##c.std_pct_Trump, ab(fips fips_state#date) cl(fips)
esttab T6B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 6 Panel B) keep(1.post*#*std* 1.post_lockdown) order(1.post*#*std*  1.post_lockdown) replace

* Panel C (controlling for political preferences)
eststo clear
eststo T6C1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin post_lockdown##c.std_pct_Trump, ab(fips date) cl(fips)
eststo T6C2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin post_lockdown##c.std_pct_Trump, ab(fips fips_state#date) cl(fips)
eststo T6C3: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin post_lockdown##c.std_pct_Trump, ab(fips date) cl(fips)
eststo T6C4: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin post_lockdown##c.std_pct_Trump, ab(fips fips_state#date) cl(fips)
esttab T6C*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 6 Panel C) keep(1.post*#*tfe_bin* 1.post*#*std* 1.post_lockdown) order(1.post*#*tfe_bin* 1.post*#*std* 1.post_lockdown) replace

******************************************************************************** 
* Table A6 (Pepublican vs. Democratic Counties)
********************************************************************************
* Panel A (social distancing variables from SafeGraph)
eststo clear
eststo TA6A1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if maj_party=="republican", ab(fips date) cl(fips)
eststo TA6A2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if maj_party=="democrat", ab(fips date) cl(fips)
eststo TA6A3: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if maj_party=="republican", ab(fips fips_state#date) cl(fips)
eststo TA6A4: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if maj_party=="democrat", ab(fips fips_state#date) cl(fips)
esttab TA6A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A6 Panel A) keep(1.post*#*tfe_bin* 1.post*) order(1.post*#*tfe_bin*) replace

* Panel B (voluntary redistribution from GofundMe)
eststo clear
eststo TA6B1: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin if maj_party=="republican", ab(fips date) cl(fips)
eststo TA6B2: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin if maj_party=="democrat", ab(fips date) cl(fips)
eststo TA6B3: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin if maj_party=="republican", ab(fips fips_state#date) cl(fips)
eststo TA6B4: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin if maj_party=="democrat", ab(fips fips_state#date) cl(fips)
esttab TA6B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A6 Panel B) keep(1.post*#*tfe_bin* 1.post*) order(1.post*#*tfe_bin*) replace

******************************************************************************** 
* Table A7 (Alternative Individualism Measures)
********************************************************************************
* Panel A (social distancing variables from SafeGraph)
eststo clear
eststo TA7A1: quietly reghdfe pct_shelter post_lockdown##c.infreq_name, ab(fips date) cl(fips)
eststo TA7A2: quietly reghdfe pct_shelter post_lockdown##c.nonpatmat_name, ab(fips date) cl(fips)
eststo TA7A3: quietly reghdfe pct_shelter post_lockdown##c.infreq_name, ab(fips fips_state#date) cl(fips)
eststo TA7A4: quietly reghdfe pct_shelter post_lockdown##c.nonpatmat_name,  ab(fips fips_state#date) cl(fips)
esttab TA7A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A7 Panel A) keep(1.post*#*infreq* 1.post*#*patmat* 1.post*) order(1.post*#*infreq* 1.post*#*patmat* 1.post*) replace

* Panel B (voluntary redistribution from GofundMe)
eststo clear
eststo TA7B1: quietly reghdfe pct_count_covid post_lockdown##c.infreq_name, ab(fips date) cl(fips)
eststo TA7B2: quietly reghdfe pct_count_covid post_lockdown##c.nonpatmat_name, ab(fips date) cl(fips)
eststo TA7B3: quietly reghdfe pct_count_covid post_lockdown##c.infreq_name, ab(fips fips_state#date) cl(fips)
eststo TA7B4: quietly reghdfe pct_count_covid post_lockdown##c.nonpatmat_name, ab(fips fips_state#date) cl(fips)
esttab TA7B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A7 Panel B) keep(1.post*#*infreq* 1.post*#*patmat* 1.post*) order(1.post*#*infreq* 1.post*#*patmat* 1.post*) replace

******************************************************************************** 
* Table A9 (Alternative TFE Measures: in decades; high/low - above/below median)
********************************************************************************
* Panel A (social distancing variables from SafeGraph)
eststo TA9A1: quietly reghdfe pct_shelter post_lockdown##c.tfe_decade, ab(fips date) cl(fips)
eststo TA9A2: quietly reghdfe pct_shelter post_lockdown##c.high_tfe, ab(fips date) cl(fips)
eststo TA9A3: quietly reghdfe pct_shelter post_lockdown##c.tfe_decade, ab(fips fips_state#date) cl(fips)
eststo TA9A4: quietly reghdfe pct_shelter post_lockdown##c.high_tfe, ab(fips fips_state#date) cl(fips)
esttab TA9A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A9 Panel A) keep(1.post*#*tfe_decade* 1.post*#*high_tfe* 1.post*) order(1.post*#*tfe_decade* 1.post*#*high_tfe* 1.post*) replace

* Panel B (voluntary redistribution from GofundMe)
eststo TA9B1: quietly reghdfe pct_count_covid post_lockdown##c.tfe_decade, ab(fips date) cl(fips)
eststo TA9B2: quietly reghdfe pct_count_covid post_lockdown##c.high_tfe, ab(fips date) cl(fips)
eststo TA9B3: quietly reghdfe pct_count_covid post_lockdown##c.tfe_decade, ab(fips fips_state#date) cl(fips)
eststo TA9B4: quietly reghdfe pct_count_covid post_lockdown##c.high_tfe, ab(fips fips_state#date) cl(fips)
esttab TA9B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A9 Panel B) keep(1.post*#*tfe_decade* 1.post*#*high_tfe* 1.post*) order(1.post*#*tfe_decade* 1.post*#*high_tfe* 1.post*) replace

******************************************************************************** 
* Table A10 (Add control variables)
********************************************************************************
lab var std_pvote2012 "voter turnout (standardized)"
lab var std_respn2010 "census response rate (standardized)"
lab var std_pop_density "population density (standardized)"
lab var std_pct_white "white population share (standardized)"
lab var std_pct_male "male population share (standardized)"

eststo TA10_1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin post_lockdown##c.std_pvote2012, ab(fips fips_state#date) cl(fips)
eststo TA10_2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin post_lockdown##c.std_respn2010, ab(fips fips_state#date) cl(fips)
eststo TA10_3: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin post_lockdown##c.std_pop_density post_lockdown##c.std_pct_white post_lockdown##c.std_pct_male, ab(fips fips_state#date) cl(fips)
eststo TA10_4: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin post_lockdown##c.std_pvote2012, ab(fips fips_state#date) cl(fips)
eststo TA10_5: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin post_lockdown##c.std_respn2010, ab(fips fips_state#date) cl(fips)
eststo TA10_6: quietly reghdfe pct_count_covid post_lockdown##c.tfe_bin post_lockdown##c.std_pop_density post_lockdown##c.std_pct_white post_lockdown##c.std_pct_male, ab(fips fips_state#date) cl(fips)
esttab TA10*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A10) keep(1.post*#*tfe_bin* 1.post*#*std* ) order(1.post*#*tfe_bin* 1.post*#*std*)  replace

******************************************************************************** 
* Table A11 (Alternative shocks to the severity of COVID)
********************************************************************************
lab var post_Trump "=1 after Trump's speech on Mar 13, 2020"
lab var lncases_l1 "lagged log number of confirmed COVID-19 cases"
xtset fips date

* Panel A (social distancing variables from SafeGraph)
eststo clear
eststo TA11A1: quietly reghdfe pct_shelter post_Trump##c.tfe_bin, ab(fips date) cl(fips)
eststo TA11A2: quietly reghdfe pct_shelter c.lncases_l1##c.tfe_bin, ab(fips date) cl(fips)
eststo TA11A3: quietly reghdfe pct_shelter post_Trump##c.tfe_bin, ab(fips fips_state#date) cl(fips)
eststo TA11A4: quietly reghdfe pct_shelter c.lncases_l1##c.tfe_bin, ab(fips fips_state#date) cl(fips)
esttab TA11A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A11 Panel A) keep(1.post_Trump*#*tfe* *lncases_l1*#*tfe* *lncases_l1*) order(1.post_Trump*#*tfe* *lncases_l1*#*tfe* *lncases_l1*)  replace

* Panel B (voluntary redistribution from GofundMe)
eststo TA11B1: quietly reghdfe pct_count_covid post_Trump##c.tfe_bin,  ab(fips date) cl(fips)
eststo TA11B2: quietly reghdfe pct_count_covid c.lncases_l1##c.tfe_bin,  ab(fips date) cl(fips)
eststo TA11B3: quietly reghdfe pct_count_covid post_Trump##c.tfe_bin,  ab(fips fips_state#date) cl(fips)
eststo TA11B4: quietly reghdfe pct_count_covid c.lncases_l1##c.tfe_bin,  ab(fips fips_state#date) cl(fips)
esttab TA11B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A11 Panel B) keep(1.post_Trump*#*tfe* *lncases_l1*#*tfe* *lncases_l1*) order(1.post_Trump*#*tfe* *lncases_l1*#*tfe* *lncases_l1*)  replace

******************************************************************************** 
* Table A12 (Dropping Counties/States with County-level Lockdowns)
********************************************************************************	
lab var county_policy_pre "=1 if county-level lockdown occurs before state lockdown, =0 otherwise"
lab var state_county_policy_pre1 "=1 if state has >=1 county-level lockdown before state lockdown, =0 otherwise"

* Panel A (without state-date fixed effects)
eststo TA12A1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin,  ab(fips date) cl(fips)
eststo TA12A2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if county_policy_pre==0,  ab(fips date) cl(fips)	
eststo TA12A3: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if state_abbr!="TX" & state_abbr!="CA", ab(fips date) cl(fips)
eststo TA12A4: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if state_county_policy_pre1==0, ab(fips date) cl(fips)
esttab TA12A*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A12 Panel A) keep(1.post*#*tfe* 1.post*) order(1.post*#*tfe* 1.post*) replace

* Panel B (with state-date fixed effects)
eststo TA12B1: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin, ab(fips fips_state#date) cl(fips)
eststo TA12B2: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if county_policy_pre==0, ab(fips fips_state#date) cl(fips)	
eststo TA12B3: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if state_abbr!="TX" & state_abbr!="CA", ab(fips fips_state#date) cl(fips)
eststo TA12B4: quietly reghdfe pct_shelter post_lockdown##c.tfe_bin if state_county_policy_pre1==0, ab(fips fips_state#date) cl(fips)
esttab TA12B*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A12 Panel B) keep(1.post*#*tfe*) order(1.post*#*tfe*) replace

******************************************************************************** 
* Figure 1, Figure A1
********************************************************************************
cd "data\us_county_shape"
use "..\rep_county_level_sample.dta", clear
keep if month(date)==4
collapse (mean)pct_shelter (sum)N_covid2=count_covid (max)tfe_bin infreq_name nonpatmat_name, by (fips)
save "..\figure_1_temp1.dta", replace

use _ID _CX _CY GEOID STATEFP fips using "usacounties.dta", clear
merge 1:m fips using "..\figure_1_temp1.dta"
erase "..\figure_1_temp1.dta"
drop if _m==2
drop _m
save "..\figure_1_temp2.dta", replace

xtset, clear
grmap, activate
drop if inlist(STATEFP, "02", "15", "43", "52", "60", "66", "69", "72", "78")
spset, modify shpfile(usacounties_shp)

format pct_shelter infreq_name nonpatmat_name %13.1f
format N_covid2 %13.0f

grmap tfe_bin, clmethod(unique) ndocolor(gs10) ndsize(vvthin) fcolor(Greys2) ocolor(gs10 ...) osize(vvthin ...) 
graph export ..\..\figures\F1a.pdf, replace	
graph export ..\..\figures_png\F1a.png, replace

grmap pct_shelter, clnumber(15) ndocolor(gs10) ndsize(vvthin) fcolor(Greys2) ocolor(gs10 ...) osize(vvthin ...) 
graph export ..\..\figures\F1b.pdf, replace	
graph export ..\..\figures_png\F1b.png, replace

grmap N_covid2, clnumber(15) ndocolor(gs10) ndsize(vvthin) fcolor(Greys2) ocolor(gs10 ...) osize(vvthin ...) 
graph export ..\..\figures\F1c.pdf, replace
graph export ..\..\figures_png\F1c.png, replace

grmap infreq_name, clnumber(15) ndocolor(gs10) ndsize(vvthin) fcolor(Greys2) ocolor(gs10 ...) osize(vvthin ...) 
graph export ..\..\figures\AF1a.pdf, replace	
graph export ..\..\figures_png\AF1a.png, replace

grmap nonpatmat_name, clnumber(15) ndocolor(gs10) ndsize(vvthin) fcolor(Greys2) ocolor(gs10 ...) osize(vvthin ...) 
graph export ..\..\figures\AF1b.pdf, replace
graph export ..\..\figures_png\AF1b.png, replace

erase "..\figure_1_temp2.dta"

cd ..
cd ..

******************************************************************************** 
* Figure A3
********************************************************************************
use "data\rep_county_level_sample.dta", clear
g week=wofd(date)
format week %tw
egen tfe3=xtile(tfe_bin), n(3) by(date)
collapse (mean) pct_shelter (sum)count_covid, by (week tfe3)
sort tfe3 week
by tfe3: g cumulative_count_covid=sum(count_covid) 

tw line pct_shelter week if (tfe3==1), yaxis(1) lpattern(solid) lcolor(black) ///
|| line pct_shelter week if (tfe3==3), yaxis(1) lpattern(dash) lcolor(gray) ///
|| , xtitle("Week", size(small)) xlabel(, labsize(small)) ///
 ytitle("Percentage of at-home devices", size(small)) ylabel(, labsize(small)) graphregion(color(white)) ///
 legend(label (1 "Bottom tercile TFE") label (2 "Top tercile TFE") size(small) row(1) order(1 2)) graphregion(margin(5 5 5 5)) 
graph export "figures\AF3a.pdf", replace	
graph export "figures_png\AF3a.png", replace	
 
tw line cumulative_count_covid week if (tfe3==1), yaxis(1) lpattern(solid) lcolor(black) ///
|| line cumulative_count_covid week if (tfe3==3), yaxis(1) lpattern(dash) lcolor(gray) ///
|| , xtitle("", size(small)) xlabel(, labsize(small)) ///
	 ytitle("Cumulative number of COVID-19 related campaigns", size(small)) ylabel(, labsize(small)) graphregion(color(white)) ///
	 legend(label (1 "Bottom tercile TFE") label (2 "Top tercile TFE") size(small) row(1) order(1 2)) graphregion(margin(5 5 5 5))
graph export "figures\AF3b.pdf", replace
graph export "figures_png\AF3b.png", replace		


******************************************************************************** 
* Figure A6(a)
********************************************************************************
use "data\rep_recovery_employment_sample.dta", clear
ren emp_combined* emp*
xtile tfe3 = tfe_bin, nq(3)
collapse (mean)emp, by (tfe3 date year month day)	
tw line emp date if (tfe3==1), yaxis(1) lpattern(solid) lcolor(black) ///
|| line emp date if (tfe3==3), yaxis(1) lpattern(dash) lcolor(gray) ///
|| , xtitle("", size(small)) xlabel(, labsize(small)) ///
 ytitle("Employment levels relative to Jan 2020", size(small)) ylabel(, labsize(small)) graphregion(color(white)) ///
 legend(label (1 "Bottom tercile TFE") label (2 "Top tercile TFE") size(small) row(1) order(1 2)) graphregion(margin(5 5 5 5))   
graph export "figures\AF6a.pdf", replace	
graph export "figures_png\AF6a.png", replace	
 
******************************************************************************** 
* Figure A6(b)
********************************************************************************	
use "data\rep_recovery_small_business_sample.dta", clear
xtile tfe3 = tfe_bin, nq(3)
collapse (mean)merchants, by (tfe3 date year month day)	
tw line merchants date if (tfe3==1), yaxis(1) lpattern(solid) lcolor(black) ///
|| line merchants date if (tfe3==3), yaxis(1) lpattern(dash) lcolor(gray) ///
|| , xtitle("", size(small)) xlabel(, labsize(small)) ///
 ytitle("Number of small businesses open relative to Jan 2020", size(small)) ylabel(, labsize(small)) graphregion(color(white)) ///
 legend(label (1 "Bottom tercile TFE") label (2 "Top tercile TFE") size(small) row(1) order(1 2)) graphregion(margin(5 5 5 5))   
graph export "figures\AF6b.pdf", replace
graph export "figures_png\AF6b.png", replace	

******************************************************************************** 
* Figure A7
********************************************************************************
use "data\rep_recovery_social_distance_sample.dta", clear
xtile tfe3 = tfe_bin, nq(3)
collapse (mean)gps_residential, by (tfe3 date year month day)	
tw line gps_residential date if (tfe3==1), yaxis(1) lpattern(solid) lcolor(black) ///
|| line gps_residential date if (tfe3==3), yaxis(1) lpattern(dash) lcolor(gray) ///
|| , xtitle("", size(small)) xlabel(, labsize(small)) ///
 ytitle("Change in at-home time relative to Jan 2020", size(small)) ylabel(, labsize(small)) graphregion(color(white)) ///
 legend(label (1 "Bottom tercile TFE") label (2 "Top tercile TFE") size(small) row(1) order(1 2)) graphregion(margin(5 5 5 5))  
graph export "figures\AF7.pdf", replace	
graph export "figures_png\AF7.png", replace

******************************************************************************** 
* Figure A4
********************************************************************************	
use "data\rep_county_level_Figure_A4_sample.dta", clear
g event_date=date-date_stayhome
g post_lockdown=(event_date>=0 & event_date<.)	

g policy_pred20=(event_date<=-21)
lab var policy_pred20 "-21"
forv t=20(-1)1 {		
	g policy_ld`t'=(event_date==-`t')	
	lab var policy_ld`t' "-`t'"
}
g policy_fd0=(event_date==0)
lab var policy_fd0 "0"
forv t=1(1)20 {		
	g policy_fd`t'=(event_date==`t')	
	lab var policy_fd`t' "`t'"
}	
g policy_postd20=(event_date>=21 & event_date<.)
lab var policy_postd20 "21"	
g zeroday=0 
lab var zeroday "-1"

global PreVarday policy_ld20-policy_ld2
global PostVarday policy_fd0-policy_fd20

quietly reghdfe pct_shelter policy_pred20 $PreVarday zeroday $PostVarday policy_postd20, ab(fips date) cl(fips_state) 
coefplot, omitted keep (policy_pred20 policy_l* zeroday policy_f* policy_postd20) vertical ciopts(recast(rcap))/*
		*/ yline(0,lpattern(dash) lc(gray)) xline(21, lc(gray)) msymbol(d)/*
		*/ xtitle("Time to/after Stay-at-home", size(small) axis(1)) xlabel(, labsize(tiny)) leg(off) /*
		*/ ytitle("Point Estimate and 95% Confidence Interval", size(small) axis(1)) ylabel(-6(2)6) ylabel(, labsize(tiny)) graphregion(color(white)) scheme(s2mono) 		
graph export "figures\AF4.pdf", replace		
graph export "figures_png\AF4.png", replace

******************************************************************************** 
* Figure A5, Table A14
********************************************************************************	
use "data\rep_county_level_Figure_A5_sample.dta", clear
g event_date=date-date_stayhome
g policy_prew4=(event_date<=-29 & event_date<.)
g policy_lw4=(event_date<=-22 & event_date>=-28)
g policy_lw3=(event_date<=-15 & event_date>=-21)
g policy_lw2=(event_date<=-8 & event_date>=-14)
g policy_lw1=(event_date<=-1 & event_date>=-7)
g policy_fw1=(event_date<=6 & event_date>=0) /*first week after the event*/
g policy_fw2=(event_date<=13 & event_date>=7)
g policy_fw3=(event_date<=20 & event_date>=14)
g policy_fw4=(event_date<=27 & event_date>=21)
g policy_fw5=(event_date<=34 & event_date>=28)
g policy_postw5=(event_date<. & event_date>=35)
lab var policy_prew4 "<-week4"
lab var policy_lw4 "-week4"
lab var policy_lw3 "-week3"
lab var policy_lw2 "-week2"
lab var policy_lw1 "-week1"
lab var policy_fw1 "week1"
lab var policy_fw2 "week2"
lab var policy_fw3 "week3"
lab var policy_fw4 "week4"
lab var policy_fw5 "week5"
lab var policy_postw5 ">week5"

global PreVar policy_prew4-policy_lw2
global PostVar policy_fw1-policy_postw5
g zero=0 
lab var zero "-week1"

eststo TA14B: reghdfe pct_shelter c.tfe_bin##$PreVar c.tfe_bin##zero c.tfe_bin##$PostVar if date>=mdy(03,01,2020) & date<mdy(05,01,2020), ab(fips fips_state#date date#tfe_bin) cl(fips)

* Appendix Figure 5
coefplot, omitted keep (1.policy_pre*#* 1.policy_l*#* 0.zero*#* 1.policy_f*#* 1.policy_post*#*)/*
			*/ coeflabel(1.policy_prew4#c.tfe_bin = "<-4" 1.policy_lw4#c.tfe_bin = "-4" 1.policy_lw3#c.tfe_bin = "-3" 1.policy_lw2#c.tfe_bin = "-2" 0.zero#c.tfe_bin = "-1" 1.policy_fw1#c.tfe_bin = "0" 1.policy_fw2#c.tfe_bin = "1" 1.policy_fw3#c.tfe_bin = "2" 1.policy_fw4#c.tfe_bin = "3" 1.policy_fw5#c.tfe_bin = "4" 1.policy_postw5#c.tfe_bin = ">4") /*
			*/ vertical ciopts(recast(rcap))/*
			*/ yline(0,lpattern(dash) lc(gray)) xline(5, lc(gray)) msymbol(d)/*
			*/ xtitle("Time to/after Stay-at-home (in weeks)", size(small) axis(1)) leg(off) /*
			*/ ytitle("Point Estimate and 95% Confidence Interval", size(small) axis(1)) graphregion(color(white)) scheme(s2mono) 
graph export "figures\AF5.pdf", replace		
graph export "figures_png\AF5.png", replace

* Appendix Table 14 Panel B (row 2)		 
esttab TA14B, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A14 Panel B (row 2)) keep (1.policy_pre*#* 1.policy_l*#* 0.zero*#* 1.policy_f*#* 1.policy_post*#*) replace			
	
* Appendix Table 14 Panel A
eststo clear
eststo week_pre1: quietly reghdfe pct_shelter tfe_bin if event_date>=-7 & event_date<0, ab(fips_state#date) cl(fips)
eststo week_post0: quietly reghdfe pct_shelter tfe_bin if event_date>=0 & event_date<=6, ab(fips_state#date) cl(fips)
eststo week_post1: quietly reghdfe pct_shelter tfe_bin if event_date>=7 & event_date<=13, ab(fips_state#date) cl(fips) 
eststo week_post2: quietly reghdfe pct_shelter tfe_bin if event_date>=14 & event_date<=20, ab(fips_state#date) cl(fips)
eststo week_post3: quietly reghdfe pct_shelter tfe_bin if event_date>=21 & event_date<=27, ab(fips_state#date) cl(fips)
eststo week_post4: quietly reghdfe pct_shelter tfe_bin if event_date>=28 & event_date<=34, ab(fips_state#date) cl(fips)
eststo week_post4plus: quietly reghdfe pct_shelter tfe_bin if event_date>=35 & event_date<., ab(fips_state#date) cl(fips)

esttab week*, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A14 Panel A) keep(tfe_bin) replace
	
log close
